package message

import "github.com/gin-gonic/gin"

type Sender struct{}

func (s Sender) SendJSON(ctx *gin.Context, v interface{}) {
	ctx.AbortWithStatusJSON(200, gin.H{"data": v})
}

func (s Sender) SendError(ctx *gin.Context, err error) {
	ctx.AbortWithStatusJSON(200, gin.H{"error": &Error{
		Code:  ErrCodeOK,
		Error: err.Error(),
	}})
}

func (s Sender) SendCodeError(ctx *gin.Context, code ErrCode, err error) {
	ctx.AbortWithStatusJSON(200, gin.H{"error": &Error{
		Code:  code,
		Error: err.Error(),
	}})
}

func (s Sender) SendMessage(ctx *gin.Context, t MsgType, msg string) {
	ctx.AbortWithStatusJSON(200, gin.H{"message": &Message{
		Type:    t,
		Message: msg,
	}})
}

func (s Sender) SendSuccessMessage(ctx *gin.Context, msg string) {
	s.SendMessage(ctx, TypeSuccess, msg)
}

func (s Sender) SendWarningMessage(ctx *gin.Context, msg string) {
	s.SendMessage(ctx, TypeWarning, msg)
}

func (s Sender) SendErrorMessage(ctx *gin.Context, msg string) {
	s.SendMessage(ctx, TypeError, msg)
}
